﻿Maiks_UI = LibStub("AceAddon-3.0"):NewAddon("Maiks_UI", "AceConsole-3.0", "AceEvent-3.0" );

SelectFrameHorizontal, SelectFrameVertical = 1,1;

function Maiks_UI:OnInitialize()
    self.db = LibStub("AceDB-3.0"):New("Maiks_UIdb", defaults, "Default")
    LibStub("AceConfig-3.0"):RegisterOptionsTable("Maiks_UI", createoptions())
    self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Maiks_UI", "Maiks: UI", "Maiks")
end

function Maiks_UI:OnEnable()
    -- Called when the addon is enabled

    -- Print a message to the chat frame
    self:Print("OnEnable Event Fired: Hello, again ;)")
end

function Maiks_UI:OnDisable()
    -- Called when the addon is disabled
end

function createoptions()

    options = {
        name = "Maiks: User Interface",
        handler = Maiks_GR,
        type = "group",
        childGroups = "tab",
        args = {
            whispergroup= {
                name = "Layout Settings",
                type = "group",
                order = 1,
                args = {
                    desc1 = {
                        name = "Maiks: User Interface\n Layout Options",
                        type = "description",
                        order = 1,
					},
                    SelectFrame = {
                        name = "Select Frame",
                        type = "select",
						values = SelectFrameTableName,
						get = function() return SelectFrameVal end,
                        set = function(info, val, _) Maiks_UI:SelectFrame(val) end,
                        order = 2,
                    },
                    PageBreak1 = {
                        name = "",
                        type = "header",
                        order = 3,
                    },
                    MoveFrameHorizontal = {
                        name = "Move Frame Horizontal",
                        type = "range",
						min = 0,
						max = ceil(WorldFrame:GetWidth()*1.4),
						step = 1,
						get = function() return SelectFrameHorizontal end,
                        set = function(info, val, _) Maiks_UI:SelectFrameHorizontal(val) end,
                        order = 4,
						width = "full",
                    },
                    MoveFrameVertical = {
                        name = "Move Frame Vertical",
                        type = "range",
						min = 0,
						max = ceil(WorldFrame:GetHeight()*1.4),
						step = 1,
						get = function() return SelectFrameVertical end,
                        set = function(info, val, _) Maiks_UI:SelectFrameVertical(val) end,
                        order = 5,
						width = "full",
                    },
                    ResizeFrameWidth = {
                        name = "Resize Frame Width",
                        type = "range",
						min = 0,
						max = 3000,
						step = 1,
						get = function() return SelectFrameWidth end,
                        set = function(info, val, _) Maiks_UI:SelectFrameWidth(val) end,
                        order = 6,
						width = "full",
                    },
                    ResizeFrameHeight = {
                        name = "Resize Frame Height",
                        type = "range",
						min = 0,
						max = 2000,
						step = 1,
						get = function() return SelectFrameHeight end,
                        set = function(info, val, _) Maiks_UI:SelectFrameHeight(val) end,
                        order = 7,
						width = "full",
                    },
                    ResizeFrameScale = {
                        name = "Resize Frame Scale",
                        type = "range",
						min = 0,
						max = 5,
						step = 0.05,
						get = function() return SelectFrameScale end,
                        set = function(info, val, _) Maiks_UI:SelectFrameScale(val) end,
                        order = 8,
						width = "full",
                    },--[[
                    FrameBackdropBorder = {
                        name = " Frame Border Backdrop ",
                        type = "select",
						get = function() return SelectFrameBackdropBorder end,
                        set = function(info, val1, val2, val3, val4, _) Maiks_UI:SelectFrameBackdropBorderColor(val1, val2, val3, val4) end,
                        order = 9,
                    },
                    FrameBackdropBorderColor = {
                        name = " Frame Border Backdrop Color",
                        type = "color",
						get = function() return SelectFrameBackdropBorderColor end,
                        set = function(info, val1, val2, val3, val4, _) Maiks_UI:SelectFrameBackdropBorderColor(val1, val2, val3, val4) end,
						hasAlpha = true,
                        order = 10,
                    },]]--
                    Reset = {
                        name = "Reset",
                        type = "execute",
						func = function() Maiks_UI:LayoutReset() end,
                        order = 99,
                    },
                },
            },
            Channelgroup = {
                name = "Info",
                type = "group",
                order = 2,
                args = {
                    desc = {
                        name = "Info about the addon",
                        type = "description",
                        order = 1.2,
                    },
                },
            },
        },
    }
    return options
end

function Maiks_UI:LayoutReset()
	MainMenuBarLeftEndCap:Show();
	MainMenuBarRightEndCap:Show();
	ReloadUI();
end

function Maiks_UI:SelectFrame(val)
	SelectFrameVal = val
	if SelectFrameVal == nil then SelectFrameVal = "1" end
	if not SelectFrameTable[SelectFrameVal]:IsShown() then SelectFrameTable[SelectFrameVal]:Show() end
	SelectFrameHorizontal, SelectFrameVertical = SelectFrameTable[SelectFrameVal]:GetCenter();
	SelectFrameWidth, SelectFrameHeight = SelectFrameTable[SelectFrameVal]:GetSize()
	return SelectFrameVal
end

function Maiks_UI:SelectFrameHorizontal(val)
	if val == nil then val = SelectFrameHorizontal
	else SelectFrameHorizontal = val end
	if not SelectFrameTable[SelectFrameVal]:IsShown() then SelectFrameTable[SelectFrameVal]:Show() end
	SelectFrameTable[SelectFrameVal]:ClearAllPoints(); 
	SelectFrameTable[SelectFrameVal]:SetPoint("CENTER", "WorldFrame", "BOTTOMLEFT", SelectFrameHorizontal, SelectFrameVertical)
	return SelectFrameHorizontal
end

function Maiks_UI:SelectFrameVertical(val)
	if val == nil then val = SelectFrameVertical
	else SelectFrameVertical = val end
	if not SelectFrameTable[SelectFrameVal]:IsShown() then SelectFrameTable[SelectFrameVal]:Show() end
	SelectFrameTable[SelectFrameVal]:ClearAllPoints(); 
	SelectFrameTable[SelectFrameVal]:SetPoint("CENTER", "WorldFrame", "BOTTOMLEFT", SelectFrameHorizontal, SelectFrameVertical)
	return SelectFrameTop
end

function Maiks_UI:SelectFrameWidth(val)
	if val == nil then val = SelectFrameWidth
	else SelectFrameWidth = val end
	SelectFrameTable[SelectFrameVal]:SetWidth(SelectFrameWidth)
end

function Maiks_UI:SelectFrameHeight(val)
	if val == nil then val = SelectFrameHeight
	else SelectFrameHeight = val end
	SelectFrameTable[SelectFrameVal]:SetHeight(SelectFrameHeight)
end

function Maiks_UI:SelectFrameScale(val)
	if val == nil then val = SelectFrameTable[SelectFrameVal]:GetScale()
	else SelectFrameScale = val end
	SelectFrameTable[SelectFrameVal]:SetScale(SelectFrameScale)
end

function Maiks_UI:SelectFrameBackdropBorderColor(val1, val2, val3, val4)
	if val1 == nil then val1, val2, val3, val4 = SelectFrameTable[SelectFrameVal]:GetBackdropBorderColor()
	else SelectFrameBackdropBorderColor = val1, val2, val3, val4 end
	SelectFrameTable[SelectFrameVal]:SetBackdropBorderColor(SelectFrameBackdropBorderColor)
end

SelectFrameTable = {
["1"] = ShoppingTooltip1,
["2"] = ShoppingTooltip2,
["3"] = ShoppingTooltip3,
["4"] = GameTooltip,
["5"] = SmallTextTooltip,
["6"] = ExampleButtonFrame,
["7"] = ModelPanningFrame,
["8"] = SideDressUpFrame,
["9"] = DressUpFrame,
["10"] = GameMenuFrame,
["11"] = UIErrorsFrame,
["12"] = AutoCompleteBox,
["13"] = StaticPopup1,
["14"] = StaticPopup2,
["15"] = StaticPopup3,
["16"] = StaticPopup4,
["17"] = VideoOptionsFrame,
["18"] = AudioOptionsFrame,
["19"] = InterfaceOptionsFrame,
["20"] = GuildChallengeAlertFrame,
["21"] = DungeonCompletionAlertFrame1,
["22"] = AlertFrame,
["23"] = MirrorTimer1,
["24"] = MirrorTimer2,
["25"] = MirrorTimer3,
["26"] = CoinPickupFrame,
["27"] = StackSplitFrame,
["28"] = ZoneTextFrame,
["29"] = SubZoneTextFrame,
["30"] = AutoFollowStatus,
["31"] = MainMenuBar,
["32"] = TalentMicroButtonAlert,
["33"] = TutorialFrame,
["34"] = TutorialFrameAlertButton,
["35"] = MinimapCluster,
["36"] = MultiBarRight,
["37"] = BuffFrame,
["38"] = ConsolidatedBuffs,
["39"] = TemporaryEnchantFrame,
["40"] = PlayerPowerBarAlt,
["41"] = PlayerBuffTimerManager,
["42"] = CastingBarFrame,
["43"] = BNToastFrame,
["44"] = BNetReportFrame,
["45"] = BNConversationInviteDialog,
["46"] = GeneralDockManager,
["47"] = ChatFrame1,
["48"] = ChatFrameMenuButton,
["49"] = FriendsMicroButton,
["50"] = ChatMenu,
["51"] = ChatFrame2,
["52"] = ChatFrame3,
["53"] = ChatFrame4,
["54"] = ChatFrame5Tab,
["55"] = ChatFrame5,
["56"] = ChatFrame6Tab,
["57"] = ChatFrame6,
["58"] = ChatFrame7Tab,
["59"] = ChatFrame7,
["60"] = ChatFrame8Tab,
["61"] = ChatFrame8,
["62"] = ChatFrame9Tab,
["63"] = ChatFrame9,
["64"] = ChatFrame10Tab,
["65"] = ChatFrame10,
["66"] = VoiceChatTalkers,
["67"] = ReadyCheckFrame,
["68"] = PlayerFrame,
["69"] = PartyMemberFrame1,
["70"] = PartyMemberFrame2,
["71"] = PartyMemberFrame3,
["72"] = PartyMemberFrame4,
["73"] = PartyMemberBackground,
["74"] = TargetFrame,
["75"] = FocusFrame,
["76"] = Boss1TargetFrame,
["77"] = Boss2TargetFrame,
["78"] = Boss3TargetFrame,
["79"] = Boss4TargetFrame,
["80"] = PetCastingBarFrame,
["81"] = StatsFrame,
["82"] = SpellBookFrame,
["83"] = CharacterFrame,
["84"] = QuestFrame,
["85"] = WatchFrame,
["86"] = QuestLogDetailFrame,
["87"] = QuestLogFrame,
["88"] = MerchantFrame,
["89"] = TradeFrame,
["90"] = ContainerFrame1,
["91"] = ContainerFrame2,
["92"] = ContainerFrame3,
["93"] = ContainerFrame4,
["94"] = ContainerFrame5,
["95"] = ContainerFrame6,
["96"] = ContainerFrame7,
["97"] = ContainerFrame8,
["98"] = ContainerFrame9,
["99"] = ContainerFrame10,
["100"] = ContainerFrame11,
["101"] = ContainerFrame12,
["102"] = ContainerFrame13,
["103"] = LootFrame,
["104"] = GroupLootFrame1,
["105"] = GroupLootFrame2,
["106"] = GroupLootFrame3,
["107"] = GroupLootFrame4,
["108"] = MissingLootFrame,
["109"] = ItemTextFrame,
["110"] = TaxiFrame,
["111"] = BankFrame,
["112"] = ScrollOfResurrectionFrame,
["113"] = FriendsFrame,
["114"] = AddFriendFrame,
["115"] = FriendsFriendsFrame,
["116"] = RaidParentFrame,
["117"] = ChannelPulloutTab,
["118"] = ChannelPullout,
["119"] = RaidWarningFrame,
["120"] = RaidBossEmoteFrame,
["121"] = ItemRefShoppingTooltip1,
["122"] = ItemRefShoppingTooltip2,
["123"] = ItemRefShoppingTooltip3,
["124"] = ItemRefTooltip,
["125"] = ComboFrame,
["126"] = TabardFrame,
["127"] = GuildRegistrarFrame,
["128"] = PetitionFrame,
["129"] = HelpFrame,
["130"] = TicketStatusFrame,
["131"] = ColorPickerFrame,
["132"] = OpacityFrame,
["133"] = OpacityFrameCloseButton,
["134"] = GossipFrame,
["135"] = MailFrame,
["136"] = StationeryPopupFrame,
["137"] = OpenMailFrame,
["138"] = PetStableFrame,
["139"] = DurabilityFrame,
["140"] = WorldStateAlwaysUpFrame,
["141"] = WorldStateScoreFrame,
["142"] = PVPFrame,
["143"] = PVPFramePopup,
["144"] = PVPBannerFrame,
["145"] = LFGDungeonReadyPopup,
["146"] = LFGInvitePopup,
["147"] = LFDRoleCheckPopup,
["148"] = LFDParentFrame,
["149"] = MovieProgressFrame,
["150"] = MacOptionsFrame,
["151"] = MacOptionsCompressFrame,
["152"] = MacOptionsCancelFrame,
["153"] = FolderPicker,
["154"] = RatingMenuFrame,
["155"] = RuneFrame,
["156"] = ChatConfigFrame,
["157"] = VehicleSeatIndicator,
["158"] = VehicleMenuBar,
["159"] = LevelUpDisplay,
["160"] = LevelUpDisplaySide,
["161"] = RolePollPopup,
["162"] = RoleChangedFrame,
["163"] = SpellActivationOverlayFrame,
["164"] = GuildInviteFrame,
["165"] = GhostFrame,
["166"] = StreamingIcon,
["167"] = IconIntroTracker,
["168"] = TimerTracker,
["169"] = CompactRaidFrameManager,
["170"] = BackpackTokenFrame,
["171"] = EventTraceFrame,
["172"] = TimeManagerFrame,
["173"] = StopwatchFrame,
["174"] = CombatLogUpdateFrame,
["175"] = CombatLogQuickButtonFrame,
["176"] = CombatText,
["177"] = MacroFrame,
["178"] = MacroPopupFrame
}
SelectFrameTableName = {
["1"] = "ShoppingTooltip1",
["2"] = "ShoppingTooltip2",
["3"] = "ShoppingTooltip3",
["4"] = "GameTooltip",
["5"] = "SmallTextTooltip",
["6"] = "ExampleButtonFrame",
["7"] = "ModelPanningFrame",
["8"] = "SideDressUpFrame",
["9"] = "DressUpFrame",
["10"] = "GameMenuFrame",
["11"] = "UIErrorsFrame",
["12"] = "AutoCompleteBox",
["13"] = "StaticPopup1",
["14"] = "StaticPopup2",
["15"] = "StaticPopup3",
["16"] = "StaticPopup4",
["17"] = "VideoOptionsFrame",
["18"] = "AudioOptionsFrame",
["19"] = "InterfaceOptionsFrame",
["20"] = "GuildChallengeAlertFrame",
["21"] = "DungeonCompletionAlertFrame1",
["22"] = "AlertFrame",
["23"] = "MirrorTimer1",
["24"] = "MirrorTimer2",
["25"] = "MirrorTimer3",
["26"] = "CoinPickupFrame",
["27"] = "StackSplitFrame",
["28"] = "ZoneTextFrame",
["29"] = "SubZoneTextFrame",
["30"] = "AutoFollowStatus",
["31"] = "MainMenuBar",
["32"] = "TalentMicroButtonAlert",
["33"] = "TutorialFrame",
["34"] = "TutorialFrameAlertButton",
["35"] = "MinimapCluster",
["36"] = "MultiBarRight",
["37"] = "BuffFrame",
["38"] = "ConsolidatedBuffs",
["39"] = "TemporaryEnchantFrame",
["40"] = "PlayerPowerBarAlt",
["41"] = "PlayerBuffTimerManager",
["42"] = "CastingBarFrame",
["43"] = "BNToastFrame",
["44"] = "BNetReportFrame",
["45"] = "BNConversationInviteDialog",
["46"] = "GeneralDockManager",
["47"] = "ChatFrame1",
["48"] = "ChatFrameMenuButton",
["49"] = "FriendsMicroButton",
["50"] = "ChatMenu",
["51"] = "ChatFrame2",
["52"] = "ChatFrame3",
["53"] = "ChatFrame4",
["54"] = "ChatFrame5Tab",
["55"] = "ChatFrame5",
["56"] = "ChatFrame6Tab",
["57"] = "ChatFrame6",
["58"] = "ChatFrame7Tab",
["59"] = "ChatFrame7",
["60"] = "ChatFrame8Tab",
["61"] = "ChatFrame8",
["62"] = "ChatFrame9Tab",
["63"] = "ChatFrame9",
["64"] = "ChatFrame10Tab",
["65"] = "ChatFrame10",
["66"] = "VoiceChatTalkers",
["67"] = "ReadyCheckFrame",
["68"] = "PlayerFrame",
["69"] = "PartyMemberFrame1",
["70"] = "PartyMemberFrame2",
["71"] = "PartyMemberFrame3",
["72"] = "PartyMemberFrame4",
["73"] = "PartyMemberBackground",
["74"] = "TargetFrame",
["75"] = "FocusFrame",
["76"] = "Boss1TargetFrame",
["77"] = "Boss2TargetFrame",
["78"] = "Boss3TargetFrame",
["79"] = "Boss4TargetFrame",
["80"] = "PetCastingBarFrame",
["81"] = "StatsFrame",
["82"] = "SpellBookFrame",
["83"] = "CharacterFrame",
["84"] = "QuestFrame",
["85"] = "WatchFrame",
["86"] = "QuestLogDetailFrame",
["87"] = "QuestLogFrame",
["88"] = "MerchantFrame",
["89"] = "TradeFrame",
["90"] = "ContainerFrame1",
["91"] = "ContainerFrame2",
["92"] = "ContainerFrame3",
["93"] = "ContainerFrame4",
["94"] = "ContainerFrame5",
["95"] = "ContainerFrame6",
["96"] = "ContainerFrame7",
["97"] = "ContainerFrame8",
["98"] = "ContainerFrame9",
["99"] = "ContainerFrame10",
["100"] = "ContainerFrame11",
["101"] = "ContainerFrame12",
["102"] = "ContainerFrame13",
["103"] = "LootFrame",
["104"] = "GroupLootFrame1",
["105"] = "GroupLootFrame2",
["106"] = "GroupLootFrame3",
["107"] = "GroupLootFrame4",
["108"] = "MissingLootFrame",
["109"] = "ItemTextFrame",
["110"] = "TaxiFrame",
["111"] = "BankFrame",
["112"] = "ScrollOfResurrectionFrame",
["113"] = "FriendsFrame",
["114"] = "AddFriendFrame",
["115"] = "FriendsFriendsFrame",
["116"] = "RaidParentFrame",
["117"] = "ChannelPulloutTab",
["118"] = "ChannelPullout",
["119"] = "RaidWarningFrame",
["120"] = "RaidBossEmoteFrame",
["121"] = "ItemRefShoppingTooltip1",
["122"] = "ItemRefShoppingTooltip2",
["123"] = "ItemRefShoppingTooltip3",
["124"] = "ItemRefTooltip",
["125"] = "ComboFrame",
["126"] = "TabardFrame",
["127"] = "GuildRegistrarFrame",
["128"] = "PetitionFrame",
["129"] = "HelpFrame",
["130"] = "TicketStatusFrame",
["131"] = "ColorPickerFrame",
["132"] = "OpacityFrame",
["133"] = "OpacityFrameCloseButton",
["134"] = "GossipFrame",
["135"] = "MailFrame",
["136"] = "StationeryPopupFrame",
["137"] = "OpenMailFrame",
["138"] = "PetStableFrame",
["139"] = "DurabilityFrame",
["140"] = "WorldStateAlwaysUpFrame",
["141"] = "WorldStateScoreFrame",
["142"] = "PVPFrame",
["143"] = "PVPFramePopup",
["144"] = "PVPBannerFrame",
["145"] = "LFGDungeonReadyPopup",
["146"] = "LFGInvitePopup",
["147"] = "LFDRoleCheckPopup",
["148"] = "LFDParentFrame",
["149"] = "MovieProgressFrame",
["150"] = "MacOptionsFrame",
["151"] = "MacOptionsCompressFrame",
["152"] = "MacOptionsCancelFrame",
["153"] = "FolderPicker",
["154"] = "RatingMenuFrame",
["155"] = "RuneFrame",
["156"] = "ChatConfigFrame",
["157"] = "VehicleSeatIndicator",
["158"] = "VehicleMenuBar",
["159"] = "LevelUpDisplay",
["160"] = "LevelUpDisplaySide",
["161"] = "RolePollPopup",
["162"] = "RoleChangedFrame",
["163"] = "SpellActivationOverlayFrame",
["164"] = "GuildInviteFrame",
["165"] = "GhostFrame",
["166"] = "StreamingIcon",
["167"] = "IconIntroTracker",
["168"] = "TimerTracker",
["169"] = "CompactRaidFrameManager",
["170"] = "BackpackTokenFrame",
["171"] = "EventTraceFrame",
["172"] = "TimeManagerFrame",
["173"] = "StopwatchFrame",
["174"] = "CombatLogUpdateFrame",
["175"] = "CombatLogQuickButtonFrame",
["176"] = "CombatText",
["177"] = "MacroFrame",
["178"] = "MacroPopupFrame"
}